package views
{
	import com.clouree.anelib.AneEventsDispatcher;
	
	import inerface.IAlertPanel;
	
	import main.ViewSubBase;
	
	import panel.alert.AlertPanel;
	
	public class AlertView extends ViewSubBase
	{
		private var _panel:IAlertPanel;
		
		private var infoText:String = "";
		private var yesStr:String = "";
		private var noStr:String = "";
		private var yesFunc:Function = null;
		private var noFunc:Function = null;
		
		public function AlertView()
		{
		}
		/**
		 * 按钮和事件全部为空则为自动关闭型弹窗
		 * @param text 文本内容
		 * @param yesBtn 第一按钮文本
		 * @param noBtn  第二按钮文本
		 * @param yesFunction 第一按钮点击事件
		 * @param noFunction 第二按钮点击事件
		 * 
		 */	
		public function showAlert(text:String,yesBtn:String = "", noBtn:String = "", yesFunction:Function = null, noFunction:Function = null):void
		{
			infoText = text;
			yesStr = yesBtn;
			noStr = noBtn;
			if(yesFunction is Function){
				yesFunc = new Function;
				yesFunc = yesFunction;
			}
			if(noFunction is Function){
				noFunc = new Function;
				noFunc = noFunction;
			}
			
			show();
		}
		
		public override function show():void
		{
			render();
		}
		
		protected override function render():void
		{
			if(!_panel){
				_panel = new AlertPanel();
				_panel.init(view.layout.stage,view.resourceLoader,view.lang,view.uri);
				
				_panel.closeThis = closeThis;
			}
			
			_panel.changeData(infoText,yesStr,noStr,yesFunc,noFunc);
			addView(_panel);
		}
		
		public override function clear():void
		{
			if(_panel){
				_panel.clear();
				_panel = null;
				
				yesStr = "";
				noStr = "";
				yesFunc = null;
				noFunc = null;
			}
		}
		
		public override function close():void
		{
			closeView(this);
		}
		
		private function closeThis():void
		{
			close();
//			clear();
		}
	}
}